Back to course home
0% completed
Vote For New Content
LinkedIn Hard
Max Points on a Line (hard)
Solution: Max Points on a Line
Closest Binary Search Tree Value II (hard)
Solution: Closest Binary Search Tree Value II
Word Ladder (hard)
Solution: Word Ladder
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Largest Rectangle in Histogram (hard)
Solution: Largest Rectangle in Histogram
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
House Robber II (medium)
Problem Statement
You are given an array representing the amount of money each house has. This array models a circle of houses, meaning that the first and last houses are adjacent. You are tasked with figuring out the maximum amount of money you can rob without alerting the neighbors.
The rule is: if you rob one house, you cannot rob its adjacent houses.
Example Generation
Example 1:
- Input: [4, 2, 3, 1]
- Expected Output: 7
- Justification: Rob the 1st and 3rd house, which gives 4 + 3 = 7.
Example 2:
- Input: [5, 1, 2, 5]
- Expected Output: 7
- Justification: Rob the 1st and 3rd house, which gives 5 + 2 = 7.
Example 3:
- Input: [1, 2, 3, 4, 5]
- Expected Output: 8
- Justification: Rob the 3rd and 5th house, which gives 3 + 5 = 8.
Constraints:
1 <= nums.length <= 1000 <= nums[i] <= 1000
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Remove Nth Node From End of List
Solution: House Robber II
Mark as Completed
On this page
Problem Statement
Example Generation
Try it yourself